package com.djhu.newscollector.crawel.imp.wangyi;

import com.djhu.newscollector.core.Holder.JobHolder;
import com.djhu.newscollector.core.dispatch.JobDispatcher;
import com.djhu.newscollector.crawel.core.PageProcess;
import com.djhu.newscollector.crawel.core.ProcessMatcher;
import com.djhu.newscollector.crawel.core.Url;
import com.djhu.newscollector.crawel.imp.worker.MongoService;
import com.djhu.newscollector.crawel.net.Page;

/**
 * Created by zw on 2018/2/12.
 */
public class WangyiProcessMatcher implements ProcessMatcher {

    private JobHolder jobHolder;

    private JobDispatcher jobDispatcher;

    private MongoService mongoService;

    @Override
    public PageProcess match(Url url) {
        String str = url.getUrl();
        if(str.contains("hongcai")){
            return new DefaultPageProcess();
        }
        if (str.contains("photoview") && str.contains("163")){
            PhotoviewProcess process = new PhotoviewProcess();
            process.setMongoService(mongoService);
            return process;
        }else if (str.contains("163") && str.contains("html")){
            WangyiNewsProcess wangyiNewsProcess = new WangyiNewsProcess();
            wangyiNewsProcess.setJobDispatcher(jobDispatcher);
            wangyiNewsProcess.setMongoService(mongoService);
            wangyiNewsProcess.setJobHolder(jobHolder);
            return  wangyiNewsProcess;
        }
        else if ( str.contains("163")  ){
            LinkPageProcess linkPageProcess = new LinkPageProcess();
            linkPageProcess.setJobDispatcher(jobDispatcher);
            linkPageProcess.setJobHolder(jobHolder);
            return linkPageProcess;
        }else {
            return new DefaultPageProcess();
        }
    }

    public JobHolder getJobHolder() {
        return jobHolder;
    }

    public void setJobHolder(JobHolder jobHolder) {
        this.jobHolder = jobHolder;
    }

    public JobDispatcher getJobDispatcher() {
        return jobDispatcher;
    }

    public void setJobDispatcher(JobDispatcher jobDispatcher) {
        this.jobDispatcher = jobDispatcher;
    }

    public MongoService getMongoService() {
        return mongoService;
    }

    public void setMongoService(MongoService mongoService) {
        this.mongoService = mongoService;
    }
}